from esapi.core import ESAPI

### FILTERS ###

def encode_for_html(value):
    return ESAPI.encoder().encode_for_html(value)

def encode_for_html_attribute(value):
    return ESAPI.encoder().encode_for_html_attribute(value)

def encode_for_javascript(value):
    return ESAPI.encoder().encode_for_javascript(value)
    
### HELPER METHODS ###

def render_template(templatename, **kwargs):
    mytemplate = env.get_template(templatename)
    return mytemplate.render(**kwargs)
    
### MAKE THE ENVIRONMENT ###

from jinja2 import Template, FileSystemLoader, Environment

env = Environment(extensions=['jinja2.ext.with_'], trim_blocks=True)
env.filters['encode_for_html'] = encode_for_html
env.filters['encode_for_html_attribute'] = encode_for_html_attribute
env.filters['encode_for_javascript'] = encode_for_javascript
env.loader = FileSystemLoader('templates')

